package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

/**
 * 商品主表
 */
@Entity
public class Product {
    private int productId;
    private String productName;
    private String productBrand;

    private ProClassily proClassily;        // 产品分类
    private List<ProDetail> proDetails;

    @ManyToOne
    @JoinColumn(name="pro_classily_id",referencedColumnName = "pro_classily_id")
    public ProClassily getProClassily() {
        return proClassily;
    }

    public void setProClassily(ProClassily proClassily) {
        this.proClassily = proClassily;
    }

    @OneToMany(mappedBy = "product")
    public List<ProDetail> getProDetails() {
        return proDetails;
    }

    public void setProDetails(List<ProDetail> proDetails) {
        this.proDetails = proDetails;
    }

    @Id
    @Column(name = "product_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    @Basic
    @Column(name = "product_name", nullable = true, length = 40)
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @Basic
    @Column(name = "product_brand", nullable = true, length = 40)
    public String getProductBrand() {
        return productBrand;
    }

    public void setProductBrand(String productBrand) {
        this.productBrand = productBrand;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Product product = (Product) o;
        return productId == product.productId &&
                Objects.equals(productName, product.productName) &&
                Objects.equals(productBrand, product.productBrand) &&
                Objects.equals(proClassily, product.proClassily) &&
                Objects.equals(proDetails, product.proDetails);
    }

    @Override
    public int hashCode() {
        return Objects.hash(productId, productName, productBrand, proClassily, proDetails);
    }

    @Override
    public String toString() {
        return "Product{" +
                "productId=" + productId +
                ", productName='" + productName + '\'' +
                ", productBrand='" + productBrand + '\'' +
                ", proClassily=" + proClassily +
                ", proDetails=" + proDetails +
                '}';
    }
}
